Repository navigation
Conversation
…t pyrefly Annotate the workflow tool node test and the rag extractor helper test so both pass the strict pyrefly project check, then drop their entries from project-excludes. Thirty-two diagnostics are cleared, all with real types: return annotations on the test methods, parameter annotations on the node and document factories, and typed stand-ins where an empty container or a `SimpleNamespace` left the element type unknown. Assertions and the exercised paths are unchanged. No ignores, no casts, no typing.Any.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-11-18 10:48:58.776697525 +0000
+++ /tmp/pyrefly_pr.txt 2026-11-18 10:48:39.772579436 +0000
@@ -1672,10 +1672,6 @@
--> tests/e2e_tests/contracts/core/workflow/nodes/test_if_else.py:388:19
ERROR Argument `dict[str, list[dict[str, list[dict[str, list[str] | str]] | str]] | str]` is not assignable to parameter `node_data` with type `IfElseNodeData | dict[str, object]` in function `_build_if_else_node` [bad-argument-type]
--> tests/e2e_tests/contracts/core/workflow/nodes/test_if_else.py:453:19
-ERROR Argument `_StubToolRuntime` is not assignable to parameter `runtime` with type `ToolNodeRuntimeProtocol` in function `graphon.nodes.tool.tool_node.ToolNode.__init__` [bad-argument-type]
- --> tests/e2e_tests/contracts/core/workflow/nodes/tool/test_tool_node.py:112:17
-ERROR Argument `Iterator[ToolRuntimeMessage]` is not assignable to parameter `messages` with type `Generator[ToolRuntimeMessage]` in function `graphon.nodes.tool.tool_node.ToolNode._transform_message` [bad-argument-type]
- --> tests/e2e_tests/contracts/core/workflow/nodes/tool/test_tool_node.py:128:18
ERROR Argument `list[ParagraphInputConfig]` is not assignable to parameter `inputs` with type `list[FormInputConfig]` in function `tests.helpers.unit.libs._human_input.support.FormService.create_form` [bad-argument-type]
--> tests/e2e_tests/contracts/libs/_human_input/test_form_service.py:311:34
ERROR `-` is not supported between `None` and `datetime` [unsupported-operation]
@@ -4870,67 +4866,67 @@
ERROR `SimpleNamespace` is not assignable to attribute `runtime_state` with type `RuntimeState` [bad-assignment]
--> tests/unit_tests/core/workflow/test_node_factory.py:1504:37
ERROR Object of class `object` has no attribute `parent_trace_context` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1184:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1185:16
ERROR Object of class `object` has no attribute `trace_session_id` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1225:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1226:16
ERROR Argument `object` is not assignable to parameter `message` with type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` in function `core.workflow.node_runtime.DifyToolNodeRuntime._convert_message_payload` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1318:52
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1319:52
ERROR Argument `object` is not assignable to parameter `message` with type `ToolInvokeMessage.BlobChunkMessage | ToolInvokeMessage.BlobMessage | ToolInvokeMessage.FileMessage | ToolInvokeMessage.JsonMessage | ToolInvokeMessage.LogMessage | ToolInvokeMessage.RetrieverResourceMessage | ToolInvokeMessage.TextMessage | ToolInvokeMessage.VariableMessage | None` in function `core.workflow.node_runtime.DifyToolNodeRuntime._convert_message_payload` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1325:46
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1326:46
ERROR `object | None` is not assignable to attribute `model_runtime` with type `LLMModelRuntime` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1444:30
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1445:30
ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1508:60
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1509:60
ERROR Object of class `ExternalRecipient` has no attribute `reference_id` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1533:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1534:16
ERROR Argument `object` is not assignable to parameter `method` with type `EmailDeliveryMethod | InstantMessageDeliveryMethod | InteractiveSurfaceDeliveryMethod` in function `core.workflow.node_runtime.apply_dify_debug_email_recipient` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1548:49
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1549:49
ERROR Argument `_ModelInstanceStub` is not assignable to parameter `model_instance` with type `ModelInstance` in function `core.workflow.node_runtime.DifyPreparedLLM.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1571:36
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1569:36
ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1590:9
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1588:9
ERROR Argument `_ModelInstanceStub` is not assignable to parameter `model_instance` with type `ModelInstance` in function `core.workflow.node_runtime.DifyPreparedLLM.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1604:36
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1602:36
ERROR Argument `_ModelInstanceStub` is not assignable to parameter `model_instance` with type `ModelInstance` in function `core.workflow.node_runtime.DifyPreparedLLM.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1612:36
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1610:36
ERROR Argument `SimpleNamespace` is not assignable to parameter `model_instance` with type `ModelInstance` in function `core.workflow.node_runtime.DifyPreparedLLM.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1639:36
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1637:36
ERROR Argument `_ModelInstanceStub` is not assignable to parameter `model_instance` with type `ModelInstance` in function `core.workflow.node_runtime.DifyPreparedPollingLLM.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1664:43
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1662:43
ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1729:9
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1727:9
ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1767:9
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1765:9
ERROR Object of class `FunctionType` has no attribute `side_effect` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1804:9
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1802:9
ERROR Object of class `FunctionType` has no attribute `call_count` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1818:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1816:16
ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1835:9
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1833:9
ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1865:9
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1863:9
ERROR Argument `_ModelInstanceStub` is not assignable to parameter `model_instance` with type `ModelInstance` in function `core.workflow.node_runtime.DifyPreparedPollingLLM.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1902:43
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1900:43
ERROR Argument `Literal['chat']` is not assignable to parameter `model_mode` with type `LLMMode` in function `core.workflow.node_runtime.DifyPromptMessageSerializer.serialize` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1919:24
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1917:24
ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:1948:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:1946:16
ERROR Argument `object` is not assignable to parameter `variable_pool` with type `VariablePool | None` in function `core.workflow.node_runtime.DifyToolNodeRuntime.get_runtime` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:2182:27
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:2180:27
ERROR Object of class `object` has no attribute `tool` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:2186:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:2184:16
ERROR Object of class `object` has no attribute `parent_trace_context` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:2187:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:2185:16
ERROR Object of class `object` has no attribute `trace_session_id` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:2210:9
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:2208:9
ERROR Argument `object` is not assignable to parameter `variable_pool` with type `VariablePool | None` in function `core.workflow.node_runtime.DifyToolNodeRuntime.get_runtime` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:2227:27
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:2225:27
ERROR Object of class `object` has no attribute `trace_session_id` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:2231:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:2229:16
ERROR Argument `object` is not assignable to parameter `variable_pool` with type `VariablePool | None` in function `core.workflow.node_runtime.DifyToolNodeRuntime.get_runtime` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:2259:27
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:2257:27
ERROR Object of class `object` has no attribute `tool` [missing-attribute]
- --> tests/unit_tests/core/workflow/test_node_runtime.py:2262:16
+ --> tests/unit_tests/core/workflow/test_node_runtime.py:2260:16
WARN Cannot instantiate `BaseNodeData` because it directly extends `ABC` or uses `ABCMeta` [direct-abstract-base-instantiation]
--> tests/unit_tests/core/workflow/test_workflow_entry.py:1010:50
ERROR `in` is not supported between `Literal['Maximum execution steps exceeded: 3 > 2']` and `None` [not-iterable]
|
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #46341 +/- ##
==========================================
- Coverage 90.41% 90.39% -0.02%
==========================================
Files 6334 6380 +46
Lines 396673 404727 +8054
Branches 79711 80909 +1198
==========================================
+ Hits 358637 365846 +7209
- Misses 31928 32478 +550
- Partials 6108 6403 +295
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
# Conflicts: # api/tests/unit_tests/pyrefly.toml
|
|
||
| stream.read = Mock(side_effect=tracked_read) | ||
| reads.append(stream.read) | ||
| reader = Mock(side_effect=tracked_read) |
There was a problem hiding this comment.
Addressed: detect_file_encodings now accepts the production FileSampleReader Protocol with the real read_file_sample as its default. The test injects a recording reader that opens the actual temporary file and verifies the sample bounds.
| self, monkeypatch: pytest.MonkeyPatch, tmp_path: Path, no_match: bool | ||
| ): | ||
| ) -> None: | ||
| class FakeResult: |
|
|
||
| def test_detect_file_encodings_timeout(self, monkeypatch: pytest.MonkeyPatch): | ||
| def test_detect_file_encodings_timeout(self, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| class FakeFuture: |
…e-and-extractor-helpers Resolve the pyrefly.toml excludes conflict by dropping all four graduated entries: this branch graduates test_helpers.py and tool/test_tool_node.py, upstream graduated test_markdown_extractor.py and test_list_operator.py. No file stays excluded on either side.
…yrefly-tool-node-and-extractor-helpers Resolve the `project-excludes` conflict: upstream graduated `core/workflow/test_node_runtime.py` in another PR, so that entry stays excluded, while this branch's own `../e2e_tests/contracts/core/workflow/nodes/tool/test_tool_node.py` stays graduated here.
There was a problem hiding this comment.
4 inline suggestions at 8e94ecac5c, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
4 inline suggestions at 34dd9e7fd8, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong.
dify-codereview
| return False | ||
|
|
||
| def submit(self, fn, file_path): | ||
| def submit[**P]( |
There was a problem hiding this comment.
This forwards to another callable, so use a ParamSpec: def f[**P](*args: P.args, **kwargs: P.kwargs), and the signature follows the callable it wraps.
dify-codereview · precise-types (paramspec) Learned from an earlier review. Reply here if this is wrong.
There was a problem hiding this comment.
Addressed: the forwarding method now uses the wrapped callable's ParamSpec via submit[**P](..., *args: P.args, **kwargs: P.kwargs).
The tool-file protocol and the adapter that implements it both returned a bare Generator, which says nothing about what the stream yields. pyrefly cannot infer the three generic parameters and rejects the annotation. The stream is read chunk by chunk as bytes everywhere it is consumed, which matches the storage backends: aliyun_oss_storage.load_stream reads 4096-byte chunks from the object and yields them directly. Spell that out.
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at 33628effe8, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 4 earlier suggestions are still open.
dify-codereview
|
The |
The tool-runtime stub returned the incoming mapping whenever no File was injected, so the contract test accepted a value the production runtime never produces. graphon appends the result straight to the node file output, and the FileReferenceFactoryProtocol requires a File. Validate the mapping with the production ToolFileMapping shape and build the File through the real factory against a persisted ToolFile row, then assert every field against that row. Add two negative cases: a tool-file row owned by another tenant must not resolve, and a mapping without transfer_method must be rejected before any lookup. Also give DifyFileReferenceFactory.build_from_mapping and the runtime's build_file_reference their real File return type, and export the mapping shapes from factories.file_factory so tests import them instead of restating them. Verified: 6 passed in the contract suite, 124 passed across the file factory and extractor helper suites, pyrefly 0 diagnostics, ruff clean, all eight guards clean. Five mutations (storage key, remote url, tenant filter, hand-built File, skipped validation) were each caught by the new assertions.
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at de8770b8b3, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 6 review threads are still unresolved.
dify-codereview
| *, | ||
| tool_runtime: ToolRuntimeHandle, | ||
| tool_parameters: dict[str, Any], | ||
| tool_parameters: Mapping[str, Any], |
There was a problem hiding this comment.
Parse, don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/): model this data once at the boundary as a pydantic model / dataclass / TypedDict (Model.model_validate(raw)), and pass the typed value on, instead of passing dicts around and re-checking keys and types where they are used. In a test, don't build this as an ad hoc dict[str, object]: define the shape (TypedDict / model) in the production code and import it here.
dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.
There was a problem hiding this comment.
Addressed at the production boundary: valid cases use the imported production mapping types, and DifyFileReferenceFactory parses the incoming mapping with TypeAdapter(FileMapping). The raw dict in this negative case is intentionally malformed to assert rejection before the builder runs.
asukaminato0721
left a comment
There was a problem hiding this comment.
3 inline suggestions at 680fdda731, each from a rule learned from earlier reviews in this repository. Reply on a comment if it is wrong. 7 review threads are still unresolved.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
1 inline suggestion at cb4cccd401, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong. 6 review threads are still unresolved.
dify-codereview
asukaminato0721
left a comment
There was a problem hiding this comment.
Consider splitting this into smaller pull requests: it adds 263 lines of non-test code, past about 150. Split it by feature: each pull request carries one functional change together with its tests, so each feature stands on its own and can be reviewed, merged and reverted independently. A rule of thumb, not a requirement. Size counts added non-test lines; tests, lock files and snapshots do not count.
dify-codereview
Why
Two test modules are still listed in
project-excludes, so they are never checked under strict pyrefly:api/tests/e2e_tests/contracts/core/workflow/nodes/tool/test_tool_node.pyapi/tests/unit_tests/core/rag/extractor/test_helpers.pySummary
Brings both under strict checking and removes their entries from
project-excludes(208 → 206 entries).Thirty-two diagnostics are cleared with real types — return annotations on the test methods, parameter annotations on the node/document factories, and typed stand-ins where an empty container or a
SimpleNamespaceleft the element type unknown. Assertions and the exercised paths are unchanged.No
# pyrefly: ignore, no# type: ignore, notyping.cast, notyping.Any.Verification
api/tests/unit_tests, pyrefly 1.5.0-dev.1 with the repo venv interpreter):ERROR29 with all 29 being the pre-existingmissing-importnoise.WARN0. Target files residual 0.pyteston both files → 11 passed.ruff checkandruff format --checkclean.